<template>
	<view class="content">
		<template v-if="!listData.length">
			<view class="noData">
				<view class="noDataImg">
					<image src="../../static/img/noData.png" mode="" style="width: 298rpx;height: 339rpx;"></image>
				</view>
				<view class="noDataTitle">
					<view>暂无课程</view>
					<view>还没找到相关的课程哦</view>
				</view>
			</view>
		</template>
		<template v-else>
			<view class="fineArts">
				<view class="occupancy_list_item" v-for="(item,index) in listData" :key="index" @click="goDetail(item)">
					<image :src="imageUrl+item.shopCover" mode="" style="width: 182rpx;height: 172rpx;"></image>
					<view class="occupancy_rt">
						<view class="occupancy_rt_title">
							<text>{{item.shopTitle}}</text>
							<image @click="housesOperation(item)"  :src="item.isHouses?'../../static/img/Collection_out.png':'../../static/img/Collection_in.png'" mode="" style="width: 27rpx;height: 27rpx;"></image>
						</view>
						<view class="search_label">
							<text>{{item.shopCategorys}}</text>
						</view>
						<view class="occupancy_rt_address">
							<image src="../../static/img/age.png" mode="" style="width: 22rpx;height: 20rpx;"></image>
							<text>招生年龄段：{{item.mechanismAges}}岁</text>
						</view>
						<view class="occupancy_browse">
							<view>
								<!-- 山东临沂市561.12km -->
							</view>
							<view >
								<image src="../../static/img/browse.png" mode="" style="width: 26rpx;height: 20rpx;"></image>
								<text>{{item.mechanismViews}}万人浏览</text>
							</view>
							
						</view>
						
					</view>
				</view>
				<view >
					<uni-load-more :status="loadStatus"></uni-load-more>
				</view>
			</view>
		</template>
	
	</view>
</template>

<script>
	import myMixin from "../../static/js/mixin.js"
	export default{
		data(){
			return {
				hasData:false,
				id:"",
			
				listData:[],
				imageUrl:'',
				cityCode:"110101",
			}
		},
		mixins: [myMixin],
		onLoad(data) {
			this.id=data.id;
			let title=data.title;
			uni.setNavigationBarTitle({
			　　title:title
			
			})
		},
		onShow() {
			this.initData();
		},
		methods:{
			//进入详情
			goDetail(item){
				uni.navigateTo({
				    url: '../subjectSub/mechanismDetail?id='+item.id
				});
			},
			initData(){
				this.$http.get(`/api/dream/moldMechanism`,{
					areaCode:this.cityCode,
					moldId:this.id,
					pageRow:this.pageRow,
					pageSize:this.pageSize
				}).then((data)=>{
					if(data.data.code==200){
						if(this.pageRow!=1){
							this.listData=this.listData.concat(data.data.result.records);
						}else{
							this.listData=data.data.result.records;
						}
						
						this.imageUrl=data.data.imageUrl;
						if (data.data.result.records.length) {
							if (data.data.result.records.length < this.pageSize) { //判断接口返回数据量小于请求数据量，则表示此为最后一页
								this.isLoadMore = true
								this.loadStatus = 'nomore';
								
							} else {
								this.isLoadMore = false;
								this.loadStatus = 'more';
							}
						} else {
							this.isLoadMore = true
							this.loadStatus = 'nomore'
						}
					}
				}).catch(()=>{
					this.isLoadMore = true
					this.loadStatus = 'nomore'
				})
			},
			//收藏操作
			housesOperation(item){
				if(item.isHouses==1){
					this.$http.get('/api/user/userHousesOperation',{
						id:item.id,
						type:2
					}).then((data)=>{
						if(data.data.code==200){
							uni.showToast({
								title: '签到成功!',
								icon: "success",
								duration: 2000,
								
							});
							this.initData();
						}else{
							uni.showToast({
								title:data.data.message,
								icon: "none",
								duration: 2000,
								
							});
						}
					})
				}
				
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/static/css/fineArts.scss'
</style>
